<template>
	<view class="page-root-bg">
		<!-- #ifdef APP-PLUS || H5 -->
		<view style="position: fixed;top: 0;width: 100%;z-index: 9999;"
			:style="{'backgroundColor':barColor?barColor:'','height':ttop}"></view>
		<view :style="{'backgroundColor':barColor?barColor:'','padding-top':ttop}"></view>
		<!-- #endif -->
		<header-view :title="'消息'" :showLeft="false"></header-view>
		<!-- 	<view class="p-2">
			<u-search :show-action='false' v-model='keyword' @change='search' @search='search'></u-search>
		</view> -->
		<scroll-view class="content-box" scroll-y :style="{'height':contentHeight}" @scrolltolower="onBottom">
			<view class="message">
				<news-item :info="newData[currentIndex].data" bkColor="#fff"></news-item>
				<!-- <uni-load-more :status="status" icon-type="flower"></uni-load-more> -->
				<u-loadmore :status="status" icon-type="flower" bg-color="transperant" margin-top="30"
					margin-bottom="30" />
			</view>
		</scroll-view>
	</view>

</template>

<script>
	export default {
		components: {},
		data() {
			return {
				barColor: getApp().globalData.barColor,
				ttop: getApp().globalData.ttop,
				contentHeight: getApp().globalData.winHeight,
				keyword: '',


				iconType: 'flower',
				status: 'nomore ', //nomore\loadmore
				loadText: {
					loadmore: '上拉加载',
					loading: '努力加载中',
					nomore: '没有了'
				},

				page: 1,
				page_size: 10,
				total: 0,
				datalist: [{
					id: '1',
					image: '/static/img/home/news-1.png',
					title: '新城区人大代表热议政府工作报告：扬奋进之帆 谱发展新篇新城区人大代表热议政府工作报告：扬奋进之帆 谱发展新篇新城区人大代表热议政府工作报告：扬奋进之帆 谱发展新篇',
					time: '2024-04-28'
				}, {
					id: '2',
					image: '',
					title: '新城区人大代表热议政府工作报告：扬奋进之帆 谱发展新篇',
					time: '2024-04-28'
				}, {
					id: '3',
					image: '/static/img/home/news-1.png',
					title: '新城区人大代表热议政府工作报告：扬奋进之帆 谱发展新篇',
					time: '2024-04-28'
				}, {
					id: '4',
					image: '/static/img/home/news-1.png',
					title: '新城区人大代表热议政府工作报告：扬奋进之帆 谱发展新篇',
					time: '2024-04-28'
				}, {
					id: '5',
					image: '/static/img/home/news-1.png',
					title: '新城区人大代表热议政府工作报告：扬奋进之帆 谱发展新篇',
					time: '2024-04-28'
				}, {
					id: '5',
					image: '/static/img/home/news-1.png',
					title: '新城区人大代表热议政府工作报告：扬奋进之帆 谱发展新篇',
					time: '2024-04-28'
				}, {
					id: '5',
					image: '/static/img/home/news-1.png',
					title: '新城区人大代表热议政府工作报告：扬奋进之帆 谱发展新篇',
					time: '2024-04-28'
				}, {
					id: '5',
					image: '/static/img/home/news-1.png',
					title: '新城区人大代表热议政府工作报告：扬奋进之帆 谱发展新篇',
					time: '2024-04-28'
				}, {
					id: '5',
					image: '/static/img/home/news-1.png',
					title: '新城区人大代表热议政府工作报告：扬奋进之帆 谱发展新篇',
					time: '2024-04-28'
				}, {
					id: '5',
					image: '/static/img/home/news-1.png',
					title: '新城区人大代表热议政府工作报告：扬奋进之帆 谱发展新篇',
					time: '2024-04-28'
				}, {
					id: '5',
					image: '/static/img/home/news-1.png',
					title: '新城区人大代表热议政府工作报告：扬奋进之帆 谱发展新篇',
					time: '2024-04-28'
				}, {
					id: '5',
					image: '/static/img/home/news-1.png',
					title: '新城区人大代表热议政府工作报告：扬奋进之帆 谱发展新篇',
					time: '2024-04-28'
				}, {
					id: '5',
					image: '/static/img/home/news-1.png',
					title: '新城区人大代表热议政府工作报告：扬奋进之帆 谱发展新篇',
					time: '2024-04-28'
				}, {
					id: '5',
					image: '/static/img/home/news-1.png',
					title: '新城区人大代表热议政府工作报告：扬奋进之帆 谱发展新篇',
					time: '2024-04-28'
				}, {
					id: '5',
					image: '/static/img/home/news-1.png',
					title: '新城区人大代表热议政府工作报告：扬奋进之帆 谱发展新篇',
					time: '2024-04-28'
				}],

				currentIndex: 0,
				newData: [{
						newsType: '1', //动态类型1.新闻动态2.通知公告	body	true	
						keyword: '',
						newsTag: '', //动态标签(字典public_news_tag)	body	false	
						pageNo: 1,
						pageSize: 3,
						data: []
					},
					{
						newsType: '2', //动态类型1.新闻动态2.通知公告	body	true	
						keyword: '',
						newsTag: '', //动态标签(字典public_news_tag)	body	false	
						pageNo: 1,
						pageSize: 3,
						data: []
					}
				]
			}
		},
		onLoad(option) {
			this.currentIndex = 0
			this.initdata()
		},
		onReady() {

		},
		onShow() {
			this.page = 1
			// this.status = 'loading'
			// this.datalist = []
			// this.initdata()
		},
		onPullDownRefresh() {
			this.newData[this.currentIndex].pageNo = 1
			this.newData[this.currentIndex].status = 'loading'
			this.newData[this.currentIndex].data = []
			this.initdata()
			uni.stopPullDownRefresh()
		},
		methods: {
			toJump(url) {
				this.$jump.toJump(url)
			},
			onBottom() {
				if (this.newData[this.currentIndex].pageNo < Math.ceil(this.newData[this.currentIndex].total / this
						.newData[this.currentIndex].pageSize)) {
					this.newData[this.currentIndex].status = 'loading';
					this.newData[this.currentIndex].pageNo = ++this.newData[this.currentIndex].pageNo;
					this.initdata()
				} else {
					this.newData[this.currentIndex].status = 'nomore';
					return
				}
			},
			calltel(tel) {
				uni.makePhoneCall({
					phoneNumber: tel
				})
			},
			search() {
				this.newData[this.currentIndex].status = 'loading'
				this.newData[this.currentIndex].pageNo = 1
				this.newData[this.currentIndex].data = []
				this.initdata()
			},
			initdata() {
				let _this = this;
				let param = this.newData[this.currentIndex]
				// 获取动态
				this.$api.common.queryPublicNews(param).then((res) => {
					if (res.code == 200) {
						if (this.newData[this.currentIndex].pageNo == 1) {
							this.newData[this.currentIndex].data = []
						}
						this.newData[this.currentIndex].total = res.result.total
						this.newData[this.currentIndex].data.push(...res.result.records)
					} else {
						this.$modal.toast(res.message)
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.page-root-bg {
		width: 100vw;
		height: 100vh;
		background: url('@/static/img/bg.png');
		background-size: 100% 100%;

		.content-box {
			width: 100%;
			height: 88%;
			padding: 20rpx;
		}
	}

	.message {
		background-color: #fff;
		border-radius: 10rpx;
		padding: 0 20rpx;
	}
</style>